#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int T, n, a[N], b[N];
int main() {
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> T;
    while(T--) {
        memset(a, 0, sizeof(a));
        cin >> n;
        for(int i = 1; i <= n; i++) {
            cin >> a[i];
            b[i] = a[i];
        }
        sort(b + 1, b + n + 1);
        int len = unique(b + 1, b + n + 1) - b - 1;
        if(len == n) {
            cout << 0 << '\n';
        } else {
            int ans = 0;
            for(int i = 1; i <= n; i++) {
                for(int j = i + 1; j <= n; j++) {
                    if(a[j] == a[i]) {
                        ans += a[i];
                        break;
                    }
                }
            }
            cout << ans << '\n';
        }
    }
    return 0;
}
/*
15
5 3 7 2 4 13 11 6 5 5 3 5 12 8 13
*/
